package cn.yuanqiao.web.controller.archive.shuzihua;

import cn.yuanqiao.archive.appManager.domain.TenantYqFolder;
import cn.yuanqiao.archive.shuzihua.service.DangAnJieShouService;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.enums.BusinessType;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/archive/jieShouGuanLi")
public class JieShouGuanLiController extends BaseController {
    @Autowired
    private DangAnJieShouService dangAnJieShouService;

    @Log(title = "接收按钮", businessType = BusinessType.UPDATE)
    @PostMapping("/jieshouDa")
    public AjaxResult updateYqda(@RequestParam("categoryId")Long categoryId, @RequestParam("ids")Long[] ids){
        dangAnJieShouService.jieshou(categoryId,ids);
        return AjaxResult.success();
    }

    /**
     * 添加项目
     * @param object
     * @return
     */
    @Log(title = "添加项目", businessType = BusinessType.INSERT)
    @PostMapping("/addItemDa")
    public AjaxResult addItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","12");
        array.add(object1);
        JSONObject object2 = new JSONObject();
        object2.put("name","JS_TYPE");
        object2.put("value","4");
        array.add(object2);
        dangAnJieShouService.addItem(object);
        return AjaxResult.success();
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PostMapping("/addFolderDa")
    public AjaxResult addFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","12");
        array.add(object1);
        JSONObject object2 = new JSONObject();
        object2.put("name","JS_TYPE");
        object2.put("value","4");
        array.add(object2);
        TenantYqFolder folder = dangAnJieShouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PostMapping("/addFolderDa1")
    public AjaxResult addFolder1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","12");
        array.add(object1);
        JSONObject object2 = new JSONObject();
        object2.put("name","JS_TYPE");
        object2.put("value","4");
        array.add(object2);
        TenantYqFolder folder = dangAnJieShouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    /**
     * 添加件
     * @param object
     * @return
     */
    @Log(title = "添加件", businessType = BusinessType.INSERT)
    @PostMapping("/addYqdaDa")
    public AjaxResult addYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","12");
        array.add(object1);
        JSONObject object2 = new JSONObject();
        object2.put("name","JS_TYPE");
        object2.put("value","4");
        array.add(object2);
        dangAnJieShouService.addYqda(object);
        return AjaxResult.success();
    }

}
